import React from "react";
import PropTypes from 'prop-types';
import {ShopService} from "../eosjs/EosService";
import {Card, Col, PageHeader, Row, Tag, Rate, Button, message} from "antd";
import {Link} from "react-router-dom";
import {CheckCircleOutlined, CloseCircleOutlined, DeleteOutlined, EditOutlined} from "@ant-design/icons";
const {Meta} = Card;
class StoreVerify extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            shopInfo: [[]]
        };

    }
    componentDidMount() {
        this.getShopInfo();
    }
    render() {
        return (
            <div className="store-verify">
                <PageHeader
                    className="site-page-header"
                    onBack={() => this.props.history.go(-1)}
                    title="店铺审核"
                    // subTitle="This is a subtitle"
                />
                {/*一行展示三个商家店铺*/}
                <Row gutter={16}>
                    {this.state.shopInfo[0].map((item, index) => {
                        return (

                            <Col span={8} key={index}>
                                <Card
                                    hoverable
                                    cover={<img alt={item.shop_name} src={item.picture_url}/>}
                                    actions={[<Button shape="circle" icon={<CloseCircleOutlined/>}
                                                      onClick={this.verifyShop.bind(this, item, false)}
                                                      danger/>,
                                        <Button shape="circle" icon={<CheckCircleOutlined />}
                                                onClick={this.verifyShop.bind(this, item, true)}
                                        />,
                                    ]}
                                >
                                    <Link to={{pathname: "/detail/" + item.sid, state: {sid: item.sid}}}><Meta
                                        title={item.shop_name + " (" + item.tag + ")"} description=""/></Link>
                                    <p>简介：{item.description}</p>
                                    <p>地址：{item.address}</p>

                                </Card>
                            </Col>
                        );
                    })}
                </Row>
            </div>
        );
    }
    getShopInfo = () => {
        let shopInfo = [];
        ShopService.getShops({is_checked: 0}, 1, 100).then(res => {
            shopInfo.push(res.rows)
            this.setState({
                shopInfo: shopInfo
            })
            console.log(this.state)
        })
    }
    verifyShop = (value, isChecked) => {
        ShopService.checkShop(value.sid, value.user, isChecked).then(res => {
            if(res.status === true){
                message.success("审核成功！");
                this.props.history.push("/verify");
            }
            else{
                message.error("审核失败！");
            }
        })
    }
}

StoreVerify.propTypes = {};

export default StoreVerify;